package org.weasel.business;

import java.util.ArrayList;

import org.weasel.data.ProjectManager;

public class Unscheduled extends Item {
	private String id;
	private ArrayList<UserStory> userStories;
	private ProjectManager projectManager;
	
	public Unscheduled(String id, ArrayList<UserStory> userStories, ProjectManager projectManager) {
		this.id = id;
		if(userStories == null){
			this.userStories = new ArrayList<UserStory>();
		}else{
			this.userStories = userStories;
		}
		this.projectManager = projectManager;
	}

	public ArrayList<UserStory> getUserStories() {
		return userStories;
	}

	public void setUserStories(ArrayList<UserStory> userStories) {
		this.userStories = userStories;
	}
	
	public UserStory addUnscheduledUserStory(UserStory story) throws Exception {
		UserStory userStory = projectManager.createUserStory(this.id, story.getName(), story.getBusinessValue(), story.getEstimatedTime(), story.getUsedTime(), story.getEffort());
		userStories.add(userStory);
		return userStory;
	}
	
	public UserStory getUnscheduledUserStory(String storyID){
		for (UserStory story : userStories) {
			if(story.getId().equals(storyID)) {
				return story;
			}
		}
		return null;
	}
	
	public void removeUnscheduledUserStory(String storyID) throws Exception {
		for(int i=0; i<userStories.size(); i++){
			if(userStories.get(i).getId().equals(storyID)) {
				userStories.remove(i);
				projectManager.deleteUserStory(storyID);
				return;
			}
		}
	}

	public String getId() {
		return id;
	}
	
}
